Containers

class Containers(dockerClient: DockerClient)

Docker containers operations using the owning DockerClient.

Result-returning methods report daemon HTTP errors as ErrorResponse. Transport/decoding failures and cancellation can throw. Live flows report request failures during collection.

Constructors

Link copied to clipboard
constructor(dockerClient: DockerClient)

Functions

Link copied to clipboard
suspend fun attach(id: String, detachKeys: String? = null, logs: Boolean = false, stream: Boolean = false, stdin: Boolean = false, stdout: Boolean = false, stderr: Boolean = false): Result<ExecSession, ErrorResponse>

Attaches to the existing container process; it does not start a new shell. The caller owns the returned ExecSession. Collect its output once and close it if never collected. Cancellation/completion of output closes the raw connection. TTY framing follows the inspected container configuration.

Link copied to clipboard
suspend fun create(name: String? = null, config: ContainerConfig = ContainerConfig()): Result<ContainerCreateResponse, ErrorResponse>
suspend fun create(name: String? = null, config: ContainerCreateRequest): Result<ContainerCreateResponse, ErrorResponse>

Creates but does not start the container. Pull the image first if absent. A name conflict is returned as an error; existing resources are not replaced.

Link copied to clipboard
suspend fun execCreate(id: String, config: ExecConfig): Result<IDResponse, ErrorResponse>

Creates an exec instance in a running container without starting its command. Pass the returned ID to Exec.startInteractive or Exec.startAndForget.

Link copied to clipboard
suspend fun export(id: String): Result<ByteReadChannel, ErrorResponse>

Returns a tar archive of the container filesystem. Read the channel to completion or cancel it. This is not a backup of data held in mounted volumes.

Link copied to clipboard
suspend fun getArchive(id: String, path: String): Result<ByteReadChannel, ErrorResponse>

Returns a tar archive of the requested container path. Read the channel to completion or cancel it.

Link copied to clipboard
suspend fun getArchiveInfo(id: String, path: String): Result<String, ErrorResponse>

Returns the raw Base64-encoded X-Docker-Container-Path-Stat header, or an empty string when absent. Decode the header separately to obtain path metadata. Bodyless HTTP errors remain error results.

Link copied to clipboard
suspend fun getChanges(id: String): Result<List<FilesystemChange>, ErrorResponse>

Get changes on a container's filesystem

Link copied to clipboard
suspend fun getInfo(id: String): Result<ContainerInspectResponse, ErrorResponse>

Inspect a container

Link copied to clipboard
suspend fun getList(all: Boolean = false, limit: Int? = null, size: Boolean = false, filters: Map<String, List<String>>? = null): Result<List<ContainerSummary>, ErrorResponse>

List containers

Link copied to clipboard
suspend fun getLogs(id: String, parameters: ContainerLogsParameters = ContainerLogsParameters()): Result<Flow<LogLine>, ErrorResponse>

Inspects the container immediately to determine TTY framing, then returns a cold flow. The log request opens during collection. HTTP errors then throw dev.limebeck.libs.docker.client.model.DockerApiException; transport, decoding and collector failures propagate. Cancellation or completion releases the request. Follow mode has no implicit timeout; the caller owns its deadline and resubscription policy.

Link copied to clipboard
suspend fun getStats(id: String, stream: Boolean = true, oneShot: Boolean = false): Result<Flow<ContainerStatsResponse>, ErrorResponse>

With stream=true, returns a cold flow whose HTTP request opens on collection. HTTP errors during collection throw dev.limebeck.libs.docker.client.model.DockerApiException; malformed samples fail collection. With stream=false, performs the request now and wraps a successful sample in a one-element flow. Cancellation releases the streaming request. CPU percentages require successive counter samples.

Link copied to clipboard
suspend fun getTop(id: String, psArgs: String? = null): Result<ContainerTopResponse, ErrorResponse>

List processes running inside a container

Link copied to clipboard
suspend fun kill(id: String, signal: String? = null): Result<Unit, ErrorResponse>

Kill a container

Link copied to clipboard
suspend fun pause(id: String): Result<Unit, ErrorResponse>

Pause a container

Link copied to clipboard
suspend fun prune(filters: Map<String, List<String>>? = null): Result<ContainerPruneResponse, ErrorResponse>

Delete unused containers

Link copied to clipboard
suspend fun putArchive(id: String, path: String, body: ByteReadChannel, noOverwriteDirNonDir: Boolean? = null, copyUIDGID: Boolean? = null): Result<Unit, ErrorResponse>

Extract an archive of files or folders into a directory in a container

Link copied to clipboard
suspend fun remove(id: String, force: Boolean = false, link: Boolean = false, v: Boolean = false): Result<Unit, ErrorResponse>

Remove a container

Link copied to clipboard
suspend fun rename(id: String, name: String): Result<Unit, ErrorResponse>

Rename a container

Link copied to clipboard
suspend fun resize(id: String, h: Int, w: Int): Result<Unit, ErrorResponse>

Changes the running container TTY dimensions. Use Exec.resize for an exec TTY.

Link copied to clipboard
suspend fun restart(id: String, signal: String? = null, t: Int? = null): Result<Unit, ErrorResponse>

Restart a container

Link copied to clipboard
suspend fun start(id: String): Result<Unit, ErrorResponse>

Starts an already-created container. Success means Docker accepted the start, not that the application is ready. A failed start does not remove the container.

Link copied to clipboard
suspend fun stop(id: String, signal: String? = null, t: Int? = null): Result<Unit, ErrorResponse>

Stop a container

Link copied to clipboard
suspend fun unpause(id: String): Result<Unit, ErrorResponse>

Unpause a container

Link copied to clipboard
suspend fun update(id: String, config: ContainerUpdateRequest): Result<ContainerUpdateResponse, ErrorResponse>

Updates supported resource limits and restart policy. Changing image, environment, ports or mounts requires recreating the container; this method does not perform that workflow.

Link copied to clipboard
suspend fun wait(id: String, condition: String? = null): Result<ContainerWaitResponse, ErrorResponse>

Wait for a container